<!DOCTYPE html>
<html class="x-admin-sm">
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="/css/font.css">
    <link rel="stylesheet" href="/css/xadmin.css">
    <script src="/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/js/xadmin.js"></script>
    <script type="text/javascript" src="/js/jquery.min.js"></script>
</head>
<style type="text/css">
    .layui-table-grid-down {
        display: none;
    }
</style>
<body>
<div class="x-nav">
            <span class="layui-breadcrumb">
                <a>首页</a>
                <a>订单管理</a>
                <a>
                    <cite>订单列表</cite>
                </a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5" >
                        <div class="layui-input-inline layui-show-xs-block">
                            <input type="text" name="name" placeholder="请输入订单号" autocomplete="off"
                                   class="layui-input">
                        </div>
                        <div class="layui-input-inline layui-show-xs-block">
                            <input type="text" name="price" placeholder="请输入订单状态" autocomplete="off"
                                   class="layui-input">
                        </div>
                        <div class="layui-input-inline layui-show-xs-block">
                            <button class="layui-btn" lay-submit="" lay-filter="search">
                                <i class="layui-icon">&#xe615;</i></button>
                        </div>
                    </form>
                </div>
                <div class="layui-card-body ">
                    <table class="layui-hide" id="test" lay-filter="demo"></table>
                </div>

            </div>
        </div>
    </div>
    <input type="hidden" id="mid" th:value="${#httpSession.getAttribute('mid')}">
</div>
</body>
<script type="text/html" id="currentTableBar">
    <a class="layui-btn" style="width: 90px;" lay-event="info">详情</a>
</script>
<script>
    var mid = $('#mid').val();
    layui.use([ 'form', 'table'],
        function () {
            var
                table = layui.table,
                form = layui.form;


            //执行一个 table 实例
            // 监听搜索操作
            form.on('submit(search)', function (data) {
                var data = data.field
                console.log(data)
                //执行搜索重载
                table.reload('test', {
                    page: false
                    , where: {
                        name: data.name,
                        isSell: data.isSell,
                        content: data.content,
                        price: data.price,
                        stock: data.stock,
                        mid: mid
                    }
                    ,url: '/product/findByProduct'
                    , parseData: function (res) { //res 即为原始返回的数据
                        console.log(res)
                        return {
                            "code": 0, //解析接口状态
                            "msg": res.msg, //解析提示文本
                            "data": res.data, //解析数据列表
                        }
                    }
                }, 'data');
                return false;
            });

            table.render({
                elem: '#test'
                , url: '/order/orderLists?mid=' + mid //数据接口
                , page: true //开启分页
                , height: 450
                , cols: [
                    [ //表头
                        {field: 'order_no', title: '订单id', width: 150, align: 'center'},
                        {field: 'sort_num', title: '取餐号', width: 90, align: 'center'}
                        , {
                        field: 'payStatus', title: '支付方式', width: 150, align: 'center', templet: function (res) {
                            if (res.payStatus == 1) {
                                return '余额支付'
                            } else {
                                return '微信支付'
                            }
                        }
                    }
                        , {field: 'review', title: '评论状态', width: 90, align: 'center',templet: function (res) {
                            if (res.review == null){
                                return '<span style="color: red">未评论</span>'
                            }else{
                                return '<span style="color: #5FB878">已评论</span>'
                            }

                        }}
                        , {field: 'remark', title: '订单备注', width: 165, align: 'center',templet: function (res) {
                            if (res.remove == null){
                                return '未备注'
                            }else {
                                return res.remove
                            }
                        }}
                        , {field: 'status', title: '订单状态', width: 90, align: 'center',templet: function (res) {
                            if (res.status == 1) {
                                return '<div style="color: red ;font-weight:bold">下单成功</div>'
                            } else if (res.status == 2){
                                return '<div style="color: green;font-weight:bold">制作中</div>'
                            } else if (res.status == 3){
                                return '<div style="color: coral;font-weight:bold">配送中</div>'
                            }else{
                                return '<div style="color: dodgerblue;font-weight:bold">订单完成</div>'
                            }
                        }}
                        , {field: 'created_at', title: '下单时间', sort: true, width: 150, align: 'center'}
                        , {field: 'completed_time', title: '完成时间', sort: true, width: 150, align: 'center'}
                        , {title: '操作',  toolbar: '#currentTableBar', align: "center"}
                    ]
                ]
                , parseData: function (res) { //res 即为原始返回的数据
                    return {
                        "code": 0, //解析接口状态
                        "msg": res.msg, //解析提示文本
                        // "count": res.data.total, //解析数据长度
                        "data": res.data //解析数据列表
                    }
                }
            });

            table.on('tool(demo)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
                const data = obj.data; //获得当前行数据
                const layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                if (layEvent === 'info') {
                    var index = layer.open({
                        title: '订单详情',
                        type: 2,
                        shade: 0.2,
                        maxmin: false,
                        shadeClose: true,
                        area: ['70%', '80%'],
                        content: '/orderDetail/orderDetails?orderId='+ data.order_no,
                    });
                    $(window).on("resize", function () {
                        layer.full(index);
                    });
                }
            })


        });

</script>
</html>